home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1993 March / Nautilus-4-3 / Nautilus-4-3.bin / Multimedia / Feature / Image 1.47 Folder / Macros / LUT Macros < prev    next >
Encoding:
Text File  |  1992-09-11  |  5.7 KB  |  305 lines

  1. macro 'Export LUT [E]';
  2. {
  3. Copies the current look-up table to the Area(Red), Mean(Green) and
  4. Perimeter/Length(blue) columns. Max Measurements must be set to
  5. 256 or greater.
  6. }
  7. var
  8.   i:integer;
  9.   v:real;
  10. begin
  11.   RequiresVersion(1.45);
  12.   SetCounter(256); 
  13.   SetOptions('Area,Mean, Perimeter');
  14.   for i:=0 to 255 do begin
  15.     rArea[i+1]:=RedLut[i];
  16.     rMean[i+1]:=GreenLut[i];
  17.     rLength[i+1]:=BlueLut[i];
  18.   end;
  19.   ShowResults;
  20.   SetExport('Measurements');
  21.   Export('RGB LUT');
  22. end;
  23.  
  24.  
  25. macro 'Invert LUT [I]';
  26. var
  27.   i:integer;
  28. begin
  29.   for i:=1 to 254 do begin
  30.     RedLUT[i]:=255-RedLut[i];
  31.     GreenLUT[i]:=255-GreenLut[i];
  32.     BlueLUT[i]:=255-BlueLut[i];
  33.   end;
  34.   UpdateLUT;
  35. end;
  36.  
  37.  
  38. macro 'Random Colors [C]';
  39. var
  40.   i,colors,entries,first,last,r,g,b:integer;
  41. begin
  42.   colors:=25;;
  43.   entries:=256/colors;
  44.   if entries>256 then entries:=256;
  45.   repeat 
  46.     first:=random*255;
  47.     last:=first+entries-1;
  48.     if last>255 then last:=255;
  49.     r:=random*255;
  50.     g:=random*255;
  51.     b:=random*255;
  52.     for i:=first to last do begin
  53.       RedLUT[i]:=r;
  54.       GreenLUT[i]:=g;
  55.       BlueLUT[i]:=b;
  56.     end;
  57.     UpdateLUT;
  58.   until button;
  59. end;
  60.  
  61.  
  62. macro 'Log Tranform';
  63. var
  64.   i,v:integer;
  65.   ln255:real;
  66. BEGIN
  67.   RedLUT[255]:=0;
  68.   GreenLUT[255]:=0;
  69.   BlueLUT[255]:=0;
  70.   ln255:=ln(255);
  71.   for i:=1 to 255 DO begin
  72.     v:=round(ln(i)*255.0/ln255);
  73.     RedLUT[255-i]:=v;
  74.     GreenLUT[255-i]:=v;
  75.     BlueLUT[255-i]:=v;
  76.   end;
  77.   UpdateLUT;
  78. END.
  79.  
  80.  
  81. macro 'Gamma Tranform [G]';
  82. var
  83.   i,v:integer;
  84.   n,mode,min,max:integer
  85.   gamma,mean:real;
  86. begin
  87.   gamma:=GetNumber('Gamma(0.1-3.0):',2);
  88.   measure;
  89.   GetResults(n,mean,mode,min,max);
  90.   ShowMessage('min=',min:1,'\max=',max:1);
  91.   for i:=1 to 254 DO begin
  92.     if (i>min) and (i<max)
  93.       then v:=exp(gamma*ln((i-min)/(max-min)))*255 {x^y=exp(y*ln(x)}
  94.       else begin
  95.         if i<=min then v:=0 else v:=255;
  96.       end;
  97.     RedLUT[i]:=255-v;
  98.     GreenLUT[i]:=255-v;
  99.     BlueLUT[i]:=255-v;
  100.   end;
  101.   UpdateLUT;
  102. end;
  103.  
  104.  
  105. macro 'Square Tranform';
  106. var
  107.   i,v:integer;
  108.   sqr255:real;
  109. BEGIN
  110.   sqr255:=sqr(255.0);
  111.   for i:=1 to 255 DO begin
  112.     v:=round(sqr(i)*255.0/sqr255);
  113.     RedLUT[255-i]:=v;
  114.     GreenLUT[255-i]:=v;
  115.     BlueLUT[255-i]:=v;
  116.   end;
  117.   UpdateLUT;
  118. END.
  119.  
  120.  
  121. macro 'Square Root Tranform';
  122. var
  123.   i,v:integer;
  124.   sqrt255:real;
  125. BEGIN
  126.   sqrt255:=sqrt(255.0);
  127.   for i:=1 to 255 DO begin
  128.     v:=round(sqrt(i)*255.0/sqrt255);
  129.     RedLUT[255-i]:=v;
  130.     GreenLUT[255-i]:=v;
  131.     BlueLUT[255-i]:=v;
  132.   end;
  133.   UpdateLUT;
  134. END;
  135.  
  136.  
  137. macro 'Reset LUT [R]';
  138. begin
  139.   ResetGrayMap;
  140. end;
  141.  
  142.  
  143. macro 'Plot LUT [P]';
  144. var
  145.   i,xscale,yscale:real;
  146.   width,height,margin,pwidth,pheight:integer;
  147.   xbase,ybase:integer;
  148. begin
  149.   SaveState;
  150.   margin:=25;
  151.   pwidth:=400;
  152.   pheight:=125;
  153.   width:=pwidth+2*margin;
  154.   height:=pheight*3+2*margin;
  155.   SetNewSize(width,height);
  156.   SetBackground(0); 
  157.   MakeNewWindow('LUT');
  158.   xscale:=(pwidth-2)/256;
  159.   yscale:=(pheight-1)/256;
  160.   SetForeground(252);
  161.   xbase:=margin; ybase:=margin;
  162.   MoveTo(xbase,ybase);
  163.   for i:=0 to 255 do
  164.     LineTo(xbase+i*xscale,ybase+RedLUT[i]*yscale);
  165.   SetForeground(255);
  166.   MakeRoi(xbase,ybase,pwidth,pheight);
  167.   FlipVertical;
  168.   DrawBoundary;
  169.   SetForeground(253);
  170.   ybase:=ybase+pheight-1;
  171.   MoveTo(xbase,ybase);
  172.   for i:=0 to 255 do
  173.     LineTo(xbase+i*xscale,ybase+GreenLUT[i]*yscale);
  174.   SetForeground(255);
  175.   MakeRoi(xbase,ybase,pwidth,pheight);
  176.   FlipVertical;
  177.   DrawBoundary;
  178.   SetForeground(254);
  179.   ybase:=ybase+pheight-1;
  180.   MoveTo(xbase,ybase);
  181.   for i:=0 to 255 do
  182.     LineTo(xbase+i*xscale,ybase+BlueLUT[i]*yscale);
  183.   SetForeground(255);
  184.   MakeRoi(xbase,ybase,pwidth,pheight);
  185.   FlipVertical;
  186.   DrawBoundary;
  187.   KillRoi;
  188.   RedLUT[252]:=255; GreenLUT[252]:=0;   BlueLUT[252]:=0;
  189.   RedLUT[253]:=0;   GreenLUT[253]:=255; BlueLUT[253]:=0;
  190.   RedLUT[254]:=0;   GreenLUT[254]:=0;   BlueLUT[254]:=255;
  191.   UpdateLUT;
  192.   SetFont('Geneva');
  193.   SetFontSize(9);
  194.   SetText('Centered');
  195.   MoveTo(margin+4,height-margin+8);
  196.   writeln(0:1:2);
  197.   MoveTo(margin+pwidth,height-margin+8);
  198.   writeln(255:1:2);
  199.   RestoreState;
  200. end;
  201.  
  202.  
  203. macro 'Show RGB Values [S]';
  204. var
  205.   x,y,v,savex,savey:integer;
  206. begin
  207.   repeat
  208.     savex:=x; savey:=y;
  209.     GetMouse(x,y);
  210.     if (x<>savex) or (y<>savey) then begin
  211.       v:=GetPixel(x,y);
  212.       ShowMessage('loc=',x:1,', ',y:1,
  213.         '\value=',v:1,
  214.         '\RGB=',RedLUT[v]:1,', ',GreenLUT[v]:1,', ',BlueLUT[v]:1);
  215.       wait(.5);
  216.     end;
  217.   until button;
  218. end;
  219.  
  220.  
  221. macro 'Posterize';
  222. var
  223.   level,i:integer
  224.   delta,steps,StepSize,NextStep:real;
  225. begin
  226.   steps:=GetNumber('Number of Gray Steps(2-256):',8);
  227.   StepSize:=256/steps;
  228.   delta:=256/(steps-1);
  229.   NextStep:=trunc(StepSize);
  230.   level:=255;
  231.   for i:=0 to 255 do begin
  232.     if i>=NextStep then begin
  233.       NextStep:=trunc(NextStep+StepSize);
  234.       level:=level-delta;
  235.       UpdateLUT;
  236.     end;
  237.     if level<0 then level:=0;
  238.     RedLUT[i]:=level;
  239.     GreenLUT[i]:=level;
  240.     BlueLUT[i]:=level;
  241.   end;
  242. end;
  243.  
  244.  
  245. macro 'Make Four Ramp LUT';
  246. var
  247.   i,entry:integer;
  248. BEGIN
  249.   entry:=0;
  250.   for i:=0 to 63 DO begin
  251.     RedLUT[entry]:=255-i*4;
  252.     GreenLUT[entry]:=255-i*4;
  253.     BlueLUT[entry]:=255-i*4;
  254.     entry:=entry+1;
  255.   end;
  256.   for i:=0 to 63 DO begin
  257.     RedLUT[entry]:=255-i*4;
  258.     GreenLUT[entry]:=0;
  259.     BlueLUT[entry]:=0;
  260.     entry:=entry+1;
  261.   end;
  262.    for i:=0 to 63 DO begin
  263.     RedLUT[entry]:=0;
  264.     GreenLUT[entry]:=255-i*4;
  265.     BlueLUT[entry]:=0;
  266.     entry:=entry+1;
  267.   end;
  268.   for i:=0 to 63 DO begin
  269.     RedLUT[entry]:=0;
  270.     GreenLUT[entry]:=0;
  271.     BlueLUT[entry]:=255-i*4;
  272.     entry:=entry+1;
  273.   end;
  274. UpdateLUT;
  275. END.
  276.  
  277. macro 'Make Composite Image'
  278. begin
  279.   SelectSlice(1);
  280.   MultiplyByConstant(0.248);
  281.   AddConstant(64);
  282.   SelectSlice(2);
  283.   MultiplyByConstant(0.248);
  284.   AddConstant(128);
  285.   SelectSlice(3);
  286.   MultiplyByConstant(0.248);
  287.   AddConstant(192);
  288. end;
  289.  
  290. macro 'Set Pixels Red';
  291. var
  292.  v:integer;
  293. begin
  294.     v:=GetNumber('Pixel Value(1-254)',10);
  295.     RedLUT[v]:=255;
  296.     GreenLUT[v]:=0;
  297.     BlueLUT[v]:=0;
  298.   end;
  299.   UpdateLUT;
  300. end;
  301.  
  302.  
  303.  
  304.  
  305.